# add current dirs to the search path
VPATH = ./src ./bin ./obj

# specify compile&link flags
CXX = mpicxx
CXXFLAGS = -Wno-deprecated -O2
INCLUDE = 

LDFLAGS =
LIBS = -lrt

# specify path&dir
srcdir = ./src
bindir = ./bin
objdir = ./obj

basenames = test baseOP row block
obj = $(patsubst %, $(objdir)/%.o, $(basenames))
goal = $(bindir)/test

# build rules
./PHONY: all info clean realclean

all: info $(objdir) $(bindir) $(goal)
	@echo $(goal) complete

# /info/ print out the compilation information like flags
info:
	@echo Build with CXXFLAGS = $(CXXFLAGS)
	@echo and LDFLAGS = $(LDFLAGS)

# /clean/ deletes everything in the bindir and the objdir
clean:
	@rm -f $(objdir)/* $(bindir)/*
	
# /realcelan/ delete the objdir and the bindir completely
realclean:
	@rm -rf $(objdir) $(bindir)
	
# build the dir in which executable will go
$(bindir):
	@mkdir -p $@
	
# build the dir in which .o files will go
$(objdir):
	@mkdir -p $@
	
# build the executables
$(goal): $(obj)
	@echo $(CXX) $(objdir)/*.o --> $@ 
	$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
	
#compilation rules
$(objdir)/test.o: test.cpp baseOP.h
	@echo $< --> $@
	$(CXX) $(INCLUDE) $(CXXFLAGS) -o $@ -c $<

$(objdir)/baseOP.o: baseOP.cpp baseOP.h
	@echo $< --> $@
	$(CXX) $(INCLUDE) $(CXXFLAGS) -o $@ -c $<
	
$(objdir)/row.o: row.cpp row.h baseOP.h
	@echo $< --> $@
	$(CXX) $(INCLUDE) $(CXXFLAGS) -o $@ -c $<
	
$(objdir)/block.o: block.cpp block.h baseOP.h
	@echo $< --> $@
	$(CXX) $(INCLUDE) $(CXXFLAGS) -o $@ -c $<		